using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;

namespace LogFileViewer
{
    public partial class MainWindow : Form
    {
        private void ChangeColumnWidth(int column)
        {
            if (listView.Columns[column].Width == 0)
            {
                listView.Columns[column].Width = sets.ConsoleWidths[column];
                sets.ColumnsVisible[column] = true;
            }
            else
            {
                listView.Columns[column].Width = 0;
                sets.ColumnsVisible[column] = false;
            }
        }
        
        /// <summary>
        ///     Clears the listview and fills it with the loaded data.
        ///     (Is not used when "Load Active Rows" is activated)
        /// </summary>
        private void PopulateListView()
        {
            listView.Items.Clear();
            for (int j = 0; j < MessageType.Length(); j++)
            {
                if (sets.SelectedTypes.Contains(MessageType.StringArray()[j]))
                {
                    List<LogEntry> entries = this.getData(j);
                    if (entries != null)
                    {
                        for (int i = 0; i < entries.Count; i++)
                        {
                            ListViewItem item = Utilities.getListViewItem(entries[i]);
                            item.Tag = i;
                            listView.Items.Add(item);
                        }
                    }
                }
            }

        }
        
        /// <summary>
        ///     Creates a context menu for the column headers of
        ///     the listview. This is needed to enable or disable
        ///     the visibility of each column.
        /// </summary>
        private void CreateListViewContextMenuItems()
        {
            contextMenuListView.Items.Clear();
            for (int i = 0; i < listView.Columns.Count; i++)
            {
                ToolStripMenuItem item = new ToolStripMenuItem(listView.Columns[i].Text);
                item.Tag = i;
                item.Checked = sets.ColumnsVisible[i];
                item.Click += new EventHandler(contextMenuItem_Click);
                contextMenuListView.Items.Add(item);
            }
        }

    }
}
